package bairui.international.model.status;

/**
 *
 * (电子券状态)State_ElectronicTicket
 */
@com.lianjing.sh.processing.info.annotation.GenerateInfoModel
@com.lianjing.sh.model.common.annotation.Comment("电子券状态")
@com.lianjing.sh.processing.info.annotation.InfoComment("电子券状态")
public enum State_ElectronicTicket implements com.sh_lianjing.state.Statable, com.sh_lianjing.standard.EnumCommentable<State_ElectronicTicket> {

	/**
	 * <b>状态:</b> </br>
	 * (未使用)Taked</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("未使用")
	@com.lianjing.sh.processing.info.annotation.InfoComment("未使用")
	Taked("未使用")
,
	/**
	 * <b>状态:</b> </br>
	 * (已生成)Generated</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已生成")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已生成")
	Generated("已生成")
,
	/**
	 * <b>状态:</b> </br>
	 * (已作废)Canceled</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已作废")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已作废")
	Canceled("已作废")
,
	/**
	 * <b>状态:</b> </br>
	 * (已使用)Used</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已使用")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已使用")
	Used("已使用")
,
	/**
	 * <b>状态:</b> </br>
	 * (已分配)Assigned</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已分配")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已分配")
	Assigned("已分配")
;

	private static java.util.Map<String, State_ElectronicTicket> Cache = new java.util.HashMap<>();
	static{
		for(State_ElectronicTicket enumItem : State_ElectronicTicket.values()){
			Cache.put(enumItem.getComment(), enumItem);
		}
	}

	private String comment;

	private State_ElectronicTicket(String comment){
		this.comment = comment;
	}

	@Override
	public String toString() {
		return comment;
	}

	@Override
	public String getComment() {
		return comment;
	}

	/**
	 * 通过备注解析状态相关
	 */
	@Override
	public State_ElectronicTicket parseByComment(String comment) {
		return State_ElectronicTicket.parse(comment);
	}

	public static State_ElectronicTicket parse(String comment) {
		State_ElectronicTicket enumItem = Cache.get(comment);
		if(null == enumItem){
			 throw new com.sh_lianjing.standard.exception.EnumCommentableException(State_ElectronicTicket.class, comment);
		}
		return enumItem;
	}

	/**
	 * from 转换方法相关
	 */
	/** <b>使用(已分配状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_use_from_Assigned() throws com.sh_lianjing.state.StateConvertException {
		if(this != Assigned){
			throw new com.sh_lianjing.state.StateConvertException(this, Used);
		}
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("使用", this, Used);
	}

	/** <b>领取(已分配状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_take_from_Assigned() throws com.sh_lianjing.state.StateConvertException {
		if(this != Assigned){
			throw new com.sh_lianjing.state.StateConvertException(this, Taked);
		}
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("领取", this, Taked);
	}

	/** <b>作废(未使用状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_cancel_from_Taked() throws com.sh_lianjing.state.StateConvertException {
		if(this != Taked){
			throw new com.sh_lianjing.state.StateConvertException(this, Canceled);
		}
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("作废", this, Canceled);
	}

	/** <b>作废(已生成状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_cancel_from_Generated() throws com.sh_lianjing.state.StateConvertException {
		if(this != Generated){
			throw new com.sh_lianjing.state.StateConvertException(this, Canceled);
		}
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("作废", this, Canceled);
	}

	/** <b>分配(已生成状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_assign_from_Generated() throws com.sh_lianjing.state.StateConvertException {
		if(this != Generated){
			throw new com.sh_lianjing.state.StateConvertException(this, Assigned);
		}
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("分配", this, Assigned);
	}

	/** <b>使用(未使用状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_use_from_Taked() throws com.sh_lianjing.state.StateConvertException {
		if(this != Taked){
			throw new com.sh_lianjing.state.StateConvertException(this, Used);
		}
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("使用", this, Used);
	}

	/** <b>领取(已生成状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_take_from_Generated() throws com.sh_lianjing.state.StateConvertException {
		if(this != Generated){
			throw new com.sh_lianjing.state.StateConvertException(this, Taked);
		}
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("领取", this, Taked);
	}

	/** <b>作废(已分配状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_cancel_from_Assigned() throws com.sh_lianjing.state.StateConvertException {
		if(this != Assigned){
			throw new com.sh_lianjing.state.StateConvertException(this, Canceled);
		}
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("作废", this, Canceled);
	}

	/** <b>生成</b> */
	public static com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_generate() {
		return new com.sh_lianjing.state.StateTransition<State_ElectronicTicket>("生成", null, Generated);
	}

	/**
	 * to 转换方法相关
	 */
	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_take_to_Taked() throws com.sh_lianjing.state.StateConvertException {
		if(this == Assigned){
			return t_take_from_Assigned();
		}else if(this == Generated){
			return t_take_from_Generated();
		}else{
			throw new com.sh_lianjing.state.StateConvertException(this, Taked);
		}
	}

	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_cancel_to_Canceled() throws com.sh_lianjing.state.StateConvertException {
		if(this == Assigned){
			return t_cancel_from_Assigned();
		}else if(this == Generated){
			return t_cancel_from_Generated();
		}else if(this == Taked){
			return t_cancel_from_Taked();
		}else{
			throw new com.sh_lianjing.state.StateConvertException(this, Canceled);
		}
	}

	public com.sh_lianjing.state.StateTransition<State_ElectronicTicket> t_use_to_Used() throws com.sh_lianjing.state.StateConvertException {
		if(this == Assigned){
			return t_use_from_Assigned();
		}else if(this == Taked){
			return t_use_from_Taked();
		}else{
			throw new com.sh_lianjing.state.StateConvertException(this, Used);
		}
	}


	/**
	 * 验证方法相关
	 */
	public Validator validator(){
		return new Validator();
	}
	
	public class Validator {
		private com.sh_lianjing.state.validate.StateCondition<State_ElectronicTicket> condition = new com.sh_lianjing.state.validate.StateCondition<>();
	
		public State_ElectronicTicket end() throws com.sh_lianjing.state.StateException{
			if(!condition.validate(State_ElectronicTicket.this)){
				throw new com.sh_lianjing.state.StateException("电子券状态错误，不能执行操作");
			}
			return State_ElectronicTicket.this;
		}
	
		/** <b>验证[未使用]状态</b> */
		public Validator v_Taked() {
			this.condition.add(Taked);
			return this;
		}
		/** <b>验证[已生成]状态</b> */
		public Validator v_Generated() {
			this.condition.add(Generated);
			return this;
		}
		/** <b>验证[已作废]状态</b> */
		public Validator v_Canceled() {
			this.condition.add(Canceled);
			return this;
		}
		/** <b>验证[已使用]状态</b> */
		public Validator v_Used() {
			this.condition.add(Used);
			return this;
		}
		/** <b>验证[已分配]状态</b> */
		public Validator v_Assigned() {
			this.condition.add(Assigned);
			return this;
		}
	}

}
